/**
 * 
 */
package com.doone.telmarket.action.web;

import java.util.Map;

import org.apache.log4j.Logger;
import org.apache.struts2.convention.annotation.InterceptorRef;
import org.apache.struts2.convention.annotation.InterceptorRefs;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.apache.struts2.interceptor.SessionAware;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.doone.telmarket.domain.Comment;
import com.doone.telmarket.service.CommentService;
import com.opensymphony.xwork2.ActionSupport;

/**
 * @author 吴同庆
 * @date 2009-10-16
 * @description
 * @package com.doone.telmarket.action.web
 */
@Controller
@Scope("prototype")
@ParentPackage("json-web")
@Results( { @Result(name = "success", type = "json") })
@InterceptorRefs( { @InterceptorRef("anonymityInterceptor"), @InterceptorRef("defaultStack") })
public class CommentPublishAction extends ActionSupport implements SessionAware {

	private static final long serialVersionUID = 4347687621177065039L;

	private final static String USER_ID = "ctUser";

	Logger log = Logger.getLogger(CommentPublishAction.class);

	@Autowired
	private CommentService commentService;

	private Map<String, Object> session;

	private Integer serviceCode;

	private String comment;

	private String nickName;

	private Comment userComment;

	public Comment getUserComment() {
		return userComment;
	}

	public void setSession(Map<String, Object> arg0) {
		session = arg0;
	}

	public void setServiceCode(Integer serviceCode) {
		this.serviceCode = serviceCode;
	}

	public void setComment(String comment) {
		this.comment = comment;
	}

	public void setNickName(String nickName) {
		this.nickName = nickName;
	}

	@Override
	public String execute() throws Exception {
		log.info("执行 comment publish execute:" + serviceCode + ":" + nickName + ":" + comment);
		String userId = (String) session.get(USER_ID);
		log.debug("userId:" + userId);
		Comment co = new Comment(serviceCode, userId, nickName, comment);
		userComment = commentService.publishComment(co);
		return SUCCESS;
	}

}
